package sk.openit.xml.stax.iterator;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

public class DbConfigReaderEchoOnly {
	private String fileName;

	public DbConfigReaderEchoOnly(String fileName) {
		this.fileName = fileName;
	}

	public void process() {
		XMLInputFactory factory = XMLInputFactory.newInstance();

		try {
			XMLEventReader r = factory.createXMLEventReader(fileName, new FileInputStream(fileName));
			while (r.hasNext()) {
				XMLEvent e = r.nextEvent();
				System.out.println(e.toString());
			}

		} catch (FileNotFoundException e) {
			System.err.println("Unable to find file: " + fileName);
			e.printStackTrace();
		} catch (XMLStreamException e) {
			System.err.println("Unable to process xml stream");
			e.printStackTrace();
		}
	}
}
